<template>
	<view class="">
		<view class="box">
			<view class="add_adress">
				<view class="add_adress_item">
					<view class="add_adress_title">收货人</view>
					<input type="text" v-model="name" placeholder="请输入收货人" placeholder-class="place" />
				</view>
			</view>
			<view class="add_adress">
				<view class="add_adress_item">
					<view class="add_adress_title">手机号码</view>
					<input type="number" @blur="check" v-model="phone" placeholder="请填写手机号码" placeholder-class="place" />
				</view>
			</view>
			<view class="add_adress" @tap="choosecity">
				<view class="add_adress_item">
					<view class="add_adress_title">收货地址</view>
					<input type="text" v-model="city" disabled="true" placeholder="点击选择收货地址" placeholder-class="place" />
				</view>
				<i class=" icon ">&#xe637;</i>
			</view>
			<view class="add_adress">
				<view class="add_adress_item">
					<view class="add_adress_title">详细地址</view>
					<input type="text" v-model="adress" placeholder="例: 6号楼301室" placeholder-class="place" />
				</view>
			</view>
			<view class="add_adress">
				<view class="add_adress_item">
					<view class="add_adress_title add_adress_title_default">设为默认地址</view>
				</view>
				 <switch color="#f73e2f" style="transform:scale(0.7)" checked />
			</view>
		</view>
		<view class="save" @tap="saveadress">保存</view>
		<w-picker
			mode="region"
			:defaultVal="['浙江省', '杭州市', '滨江区']"
			:areaCode="['33', '3301', '330108']"
			:hideArea="false"
			@confirm="onConfirm"
			ref="region"
			themeColor="#f00"
		></w-picker>
	</view>
</template>

<script>
import wPicker from '@/components/w-picker/w-picker.vue';
export default {
	components: {
		wPicker
	},
	mounted () {
		var pages = getCurrentPages();
		// console.log(pages);
		this.pageBefore = pages[pages.length - 2].route;
		console.log(this.pageBefore);
		if(this.pageBefore == 'pageD/adress/adress') {
			this.back = true
		}else {
			this.back = false
		}
	},
	data() {
		return {
			info:{},
			city: '',
			name: '',
			phone: '',
			adress: '',
			back:false
		};
	},
	methods: {
		choosecity () {
			this.$refs.region.show()
		},
		onConfirm (e) {
			console.log(e)
			this.city = e.result
		},
		check () {
			if (!/^1[3456789]\d{9}$/.test(this.phone)) {
				this.toast('手机号位数不对，请输入正确手机号')
				this.phone = ''
				return false
			}
		},
		saveadress () {
			uni.showLoading({
				title:'正在保存地址中'
			})
			setTimeout( () => {
				console.log(this.back);
				if (this.back) {
					uni.redirectTo({
						url: '/pageD/adress/adress'
					})
				}else {
					uni.redirectTo({
						url: '/pageB/order/confirmorder'
					})
				}
				uni.hideLoading()
			},1000)
		}
	}
};
</script>

<style>
page {
	background-color: #f8f8f8;
}
</style>
<style lang="less" scoped>
.box {
	width: 100%;
	background-color: #ffffff;
	padding: 0 30upx;
	box-sizing: border-box;
}
.add_adress {
	width: 100%;
	height: 118upx;
	border-bottom: 2upx solid #e1e1e1;
	display: flex;
	align-items: center;
	justify-content: space-between;
	.add_adress_item {
		display: flex;
		align-items: center;
		input {
			width: 520upx;
			font-size: 28upx;
			color: #333333;
		}
		.add_adress_title {
			width: 140upx;
			font-size: 28upx;
			color: #333;
		}
		.add_adress_title_default {
			width:200upx;
		}
	}
	.icon {
		font-size: 28upx;
		color: #999;
	}
}

.add_adress:last-child {
	border-bottom: none;
}
.save {
	width: calc(100% - 60upx);
	height: 88upx;
	margin: 30upx auto;
	background: linear-gradient(to right, #f73e2f 0%, #fc5c2f 100%);
	border-radius: 8upx;
	font-size: 32upx;
	color: #ffffff;
	text-align: center;
	line-height: 88upx;
	box-shadow: 0 2upx 10upx -2upx #f73e2f;
}
</style>
